﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ESAM_Assignment_3
{
    public partial class EditComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int CommentID = Convert.ToInt32(Request.QueryString["CommentID"]);

                CommentClass myComment = CommentClass.GetComment(CommentID);

                if (myComment != null)
                {
                    tbxComments.Text = myComment.Comment;
                    tbxSubject.Text = myComment.Subject;
                    lblDatePosted.Text = myComment.DatePosted;
                    lblCommentID.Text = CommentID.ToString();
                    lblFullname.Text = myComment.Fullname;
                }
            }
        }

        protected void btnUpdateComment_Click(object sender, EventArgs e)
        {
            int CommentID = Convert.ToInt32(lblCommentID.Text);
            string comment = tbxComments.Text;
            string subject = tbxSubject.Text;
            string datePosted = Common.InsertTodayIntoCommentsDate();

            bool status = CommentClass.UpdateComment(CommentID, comment, datePosted, subject);

            if (status)
            {
                lblStatus.Text = "Comment updated successfully.";
                lblStatus.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblStatus.Text = "Comment failed to update!!!.";
                lblStatus.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}